import redis as _redis
from typing import Optional
from intelli_port.config import load_settings


_client: Optional[_redis.Redis] = None


def get_redis() -> _redis.Redis:
    global _client
    if _client is None:
        s = load_settings()
        _client = _redis.from_url(
            s.redis_uri,
            socket_timeout=2.0,
            retry_on_timeout=True,
        )
    return _client